﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class pages_Bullitin_DisplayBullitinList : System.Web.UI.Page
{
    WebPager wp = new WebPager();   //页面分页操作类
    PageBean pageParm = new PageBean(); //页面参数类
    /// <summary>
    /// 页面加载
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            SetPageBean();  //设置页面参数
            wp.BindData(ref pager, ref dvBulletinList, pageParm, true); //执行页面数据装载,注意,最后一个参数必须默认为false;

        }
    }

    /// <summary>
    /// 执行编辑操作
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void lkbtonEdit_Click(object sender, EventArgs e)
    {
        string strPkID = ((LinkButton)sender).CommandArgument;
        Session["QueryString"] = strPkID;   //设置页面传递参数变量
        Response.Redirect("EditBullitin.aspx");
    }

    ///// <summary>
    ///// 执行数据删除操作
    ///// </summary>
    ///// <param name="sender"></param>
    ///// <param name="e"></param>
    //protected void lkbtnDel_Click(object sender, EventArgs e)
    //{
    //    string strPkID = ((LinkButton)sender).CommandArgument;
    //    EBulletin eBulletin = new EBulletin();
    //    bool b = eBulletin.DeleteBulletin(strPkID);
    //    if (b)
    //    {

    //        bool isVs = (ViewState["doSearch"] != null);    //判定是否执行的是查询结果分页
    //        if (txtTitle.Text != "" || txtBeginDate.Text != "" || txtEndDate.Text != "")
    //        {
    //            int intMark = 0;    //数据记录器,记录有多少行数据
    //            SetPageBean();
    //            wp.SearchNews(ref pager, ref dvBulletinList, ref intMark, pageParm, isVs);
    //            if (intMark == 0)
    //            {
    //                this.lblInfo.Visible = true;
    //                this.lblInfo.Text = "<font color='#FF0000'>对不起,没有找到您需要的记录!</font>";
    //            }
    //        }
    //        else
    //        {
    //            SetPageBean();
    //            wp.PageLoadBinding(ref pager, ref dvBulletinList, pageParm, isVs);
    //        }
    //        this.lblInfo.Visible = true;
    //        this.lblInfo.Text = "<font color='#006600'>已成功删除了一条记录!</font>";
    //    }
    //    else
    //    {
    //        this.lblInfo.Visible = true;
    //        this.lblInfo.Text = "<font color='#FF0000'>对不起,操作失败!</font>";

    //    }

    //}

    /// <summary>
    /// 新建公告操作
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        Response.Redirect("CreateBullitin.aspx");
    }

    ///// <summary>
    ///// 查询操作
    ///// </summary>
    ///// <param name="sender"></param>
    ///// <param name="e"></param>
    //protected void btnSearch_Click(object sender, EventArgs e)
    //{
    //    int intMark = 0;    //数据记录器,记录有多少行数据

    //    hfdTitle.Value = txtTitle.Text.Trim();
    //    hfdStartDate.Value = Request.Form[txtBeginDate.UniqueID].Trim();
    //    hfdEndDate.Value = Request.Form[txtEndDate.UniqueID].Trim();
    //    if (hfdTitle.Value != "" || hfdStartDate.Value != "" || hfdEndDate.Value != "")
    //    {

    //        ViewState["doSearch"] = "true"; //设置视图状态变量,用以区别是否进行页查询分页.
    //        pager.CurrentPageIndex = 1;     //设置起始页为1
    //        SetSearchKeyWord();
    //        SetPageBean();
    //        wp.SearchNews(ref pager, ref dvBulletinList, ref intMark, pageParm, true);
    //        if (intMark == 0)
    //        {
    //            this.lblInfo.Visible = true;
    //            this.lblInfo.Text = "<font color='#FF0000'>对不起,没有找到您需要的记录!</font>";
    //        }

    //    }
    //    else
    //    {
    //        Response.Redirect(Request.RawUrl);
    //    }
    //    hlkDispAll.Visible = true;
    //    hlkDispAll.NavigateUrl = Request.RawUrl;

    //    txtTitle.Text = hfdTitle.Value;
    //    if (hfdStartDate.Value != "")
    //    {
    //        txtBeginDate.ReadOnly = false;
    //        txtBeginDate.Text = hfdStartDate.Value;
    //        txtBeginDate.ReadOnly = true;
    //    }
    //    if (hfdEndDate.Value != "")
    //    {
    //        txtEndDate.ReadOnly = false;
    //        txtEndDate.Text = hfdEndDate.Value;
    //        txtEndDate.ReadOnly = true;
    //    }
    //}

    /// <summary>
    /// 换页事件
    /// </summary>
    /// <param name="src"></param>
    /// <param name="e"></param>
    protected void pager_PageChanged(object src, Wuqi.Webdiyer.PageChangedEventArgs e)
    {
        //txtTitle.Text = hfdTitle.Value;
        //if (hfdTitle.Value != "")
        //{
        //    txtBeginDate.ReadOnly = false;
        //    txtBeginDate.Text = hfdStartDate.Value;
        //    txtBeginDate.ReadOnly = true;
        //}
        //if (hfdEndDate.Value != "")
        //{
        //    txtEndDate.ReadOnly = false;
        //    txtEndDate.Text = hfdEndDate.Value;
        //    txtEndDate.ReadOnly = true;
        //}

        pager.CurrentPageIndex = e.NewPageIndex;
        //bool isVs = (ViewState["doSearch"] != null);
        SetPageBean();
        pageParm.PageIndex = e.NewPageIndex;
        pageParm.PageSize = pager.PageSize;

        wp.BindData(ref pager, ref dvBulletinList, pageParm, false);
    }

    #region 公有方法
    /// <summary>
    /// 设置分页参数
    /// </summary>
    protected void SetPageBean()
    {
        //this.lblInfo.Visible = false;
        pageParm.TableList = "pk_id,bulletin_code,bulletin_title,bulletin_sub_title,issue_organ,issue_emp_code,issue_emp_name,issue_datetime,bulletin_expiry_date,status";
        pageParm.TableName = "vi_oa_bulletin_emp";
        pageParm.SelectOrderID = "pk_id";
        pageParm.SelectOrder = "issue_datetime desc";
        pageParm.PageIndex = 1;
        //pageParm.SelectWhere = hfdSearchKey.Value;
        pageParm.SelectWhere = "bulletin_expiry_date >=\'" + System.DateTime.Now.ToShortDateString() + "\'";
        pageParm.PageSize = pager.PageSize;
    }

    ///// <summary>
    ///// 设置查询关键字
    ///// </summary>
    ///// <returns></returns>
    //protected void SetSearchKeyWord()
    //{

    //    string searchOrder = "";

    //    if (hfdTitle.Value != "")
    //    {

    //        searchOrder = searchOrder + "bulletin_title like \'%" + hfdTitle.Value + "%\'";
    //    }

    //    if (searchOrder != "" && hfdStartDate.Value != "")
    //    {
    //        searchOrder = searchOrder + " and issue_datetime >=\'" + hfdStartDate.Value + "\'";
    //    }
    //    else if (hfdStartDate.Value != "")
    //    {
    //        searchOrder = searchOrder + " issue_datetime >=\'" + hfdStartDate.Value + "\'";
    //    }

    //    if (searchOrder != "" && hfdEndDate.Value != "")
    //    {
    //        searchOrder = searchOrder + " and issue_datetime <\'" + hfdEndDate.Value + "\'";
    //    }
    //    else if (hfdEndDate.Value != "")
    //    {
    //        searchOrder = searchOrder + " issue_datetime <\'" + hfdEndDate.Value + "\'";
    //    }
    //    hfdSearchKey.Value = searchOrder;
    //}
    #endregion
    protected void lkbTitle_Click(object sender, EventArgs e)
    {
        string strPkID = ((LinkButton)sender).CommandArgument;
        Session["QueryString"] = strPkID;   //设置页面传递参数变量
        Response.Redirect("DispBullitin.aspx");
    }
}

